package com.proxy;

/**
 * 静态代理
 * @author zhuangqi
 * @@date 2017/5/8.
 */
public class SimpleStaticProxyDemo {

    static interface IService{
        public void sayHello();
    }

    static class RealService implements IService{

        @Override
        public void sayHello() {
            System.out.println("hello");
        }
    }

    static class TraceProxy implements IService{

        private IService realService;

        public TraceProxy(IService realService) {
            this.realService = realService;
        }

        @Override
        public void sayHello() {
            //代理前
            System.out.println("entering sayHello");
            this.realService.sayHello();
            //代理后
            System.out.println("leaving sayHello");
        }

        public static void main(String[] args) {
            IService realService = new RealService();
            IService proxyService = new TraceProxy(realService);
            proxyService.sayHello();
        }
    }
}
